#include "processbar.h"


const char* lable = "|/-\\";

void process()
{
    //printf("hello\n");
    char buffer[NUM];
    memset(buffer,'\0',sizeof(buffer));
    
    int len = strlen(lable);

    int count = 0;
    buffer[0] = '>';
    while(count <= 100)
    {
        printf("[%-100s][%3d%%][%c]\r",buffer,count,lable[count%len]);
        fflush(stdout);

        buffer[count++] = '=';
        if(count < 100)
        {
            buffer[count] = '>';
        }
        usleep(100000);
    }
    printf("\n");
}

char buffer[101] = {0};
void process_flush(double rate)
{
    static int count = 0;

    int n = (int)rate;
    if(n == 0)
        buffer[0] = '>';
    int len = strlen(lable);

    printf("[%-100s][%.1f%%][%c]\r",buffer,rate,lable[count]);
    fflush(stdout);

    ++count;
    count%=len;

    buffer[n++] = '=';
    if(n < 100 && n > 1)
    {
        buffer[n] = '>';
    }
    if(rate >= 100.0)
        printf("\n");
}



